/**
 * 
 */
package org.perfect.batch.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author billmse
 *
 */
@Configuration
public class SimpleJobConfiguration {

	@Autowired
	private JobBuilderFactory jobBuilderFactory;

	@Autowired
	private StepBuilderFactory stepBuilderFactory;

	public static final String JOB_NAME = "SimpleJob";
	public static final String STEP_NAME = "SimpleStep";
	
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Bean(JOB_NAME)
	public Job simpleJob() {
		return jobBuilderFactory.get(JOB_NAME).start(simpleStep()).build();
	}

	@Bean(STEP_NAME)
	public Step simpleStep() {
		return stepBuilderFactory.get(STEP_NAME).tasklet(new Tasklet() {

			@Override
			public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
				if (logger.isInfoEnabled()) {
					logger.info("{}", chunkContext);
				}
				return RepeatStatus.FINISHED;
			}

		}).build();
	}

}
